package com.example.demo111111.service.impl;

import com.example.demo111111.Result.PageResult;
import com.example.demo111111.dao.CategoryDao;
import com.example.demo111111.entity.Category;
import com.example.demo111111.entity.Merchant;
import com.example.demo111111.service.CategoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryDao categoryDao;

    @Override
    public Boolean save(Category category) {
        if (category.getStatus()==null){
            category.setStatus(1);
        }
        category.setCreate_time(LocalDateTime.now());
        category.setUpdate_time(LocalDateTime.now());
        Boolean result=categoryDao.save(category);
        return result;
    }

    @Override
    public Boolean update(Category category) {
        category.setUpdate_time(LocalDateTime.now());
        Boolean result=categoryDao.update(category);
        return result;
    }

    @Override
    public PageResult pageQuery(Category category) {
        PageHelper.startPage(category.getPage(),category.getPageSize());
        Page<Category> page=categoryDao.pageQuery(category);
        long total=page.getTotal();
        List<Category> records=page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public Boolean deltete(List<Long> ids) {
        Boolean result = null;
        for (Long id : ids) {
            result = categoryDao.deleteById(id);
        }
        return result;
    }
}
